package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.OperationLogRecordDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.OperationLogRecordRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: huangtao
 * @Description: 操作日志
 * @Date: create in 2020/10/5
 */
@Service
@Slf4j
public class OperationLogRecordFacade {
    @Resource
    private OperationLogRecordRemote operationLogRecordRemote;

    public PageInfo<OperationLogRecordDTO> getOperationLogs(OperationLogRecordDTO operationLogRecord){
        log.info("操作日志参数:operationLogRecord:{}",operationLogRecord);
        Response<PageInfo<OperationLogRecordDTO>> response = operationLogRecordRemote.getOperationLogs(operationLogRecord);
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public OperationLogRecordDTO insertOperationLog(OperationLogRecordDTO operationDto){
        log.info("新增操作日志数据参数:operationDto:{}", operationDto);
        Response<OperationLogRecordDTO> response= operationLogRecordRemote.insertOperationLog(operationDto);
        log.info("新增操作日志数据返回结果:response:{}", response);
        return response.getData();
    }

    public void updateOperationLog(OperationLogRecordDTO operationDto){
        log.info("编辑操作日志数据入参:{}", JSONObject.toJSONString(operationDto));
        operationLogRecordRemote.updateOperationLog(operationDto);
    }

    public void bigDataInitiating() {
        Response response = operationLogRecordRemote.bigDataInitiating();
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
    }

    public void rmByOpSign(List<OperationLogRecordDTO> operationLogRecordDTOs) {
        Response response = operationLogRecordRemote.rmByOpSign(operationLogRecordDTOs);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
    }

    public void opLogInitiating(List<Long> ids) {
        Response response = operationLogRecordRemote.opLogInitiating(ids);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
    }

    public void updateToDel(String opSign){
        log.info("修改操作日志状态为已删除参数:opSign:{}", opSign);
        operationLogRecordRemote.updateToDel(opSign);
    }
}
